import { ref } from 'vue'

function useSendPhoneCode(num = 60) {
	let codeNum = ref(num)
	let codeTtx = ref('发送验证码')

	let sendCode = () => {
		codeTtx.value = codeNum.value + 's'
		let timer = setInterval(() => {
			codeNum.value--
			codeTtx.value = codeNum.value + 's'

			if (codeNum.value === 0) {
				clearInterval(timer)
				codeTtx.value = '发送验证码'
				codeNum.value = 60
			}
		}, 1000)
	}

	return { codeTtx, sendCode }
}

export default useSendPhoneCode
